package model.agent.question;

import static org.junit.Assert.*;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;

class QuestionTest {

	@BeforeClass
	public static void setUpBeforeClass() throws Exception {
	}

	@AfterClass
	public static void tearDownAfterClass() throws Exception {
	}

	@Before
	public void setUp() throws Exception {
	}

	@After
	public void tearDown() throws Exception {
	}

	@Test
	public void testMulti() {
		QuestionInterface msq = new MultiSelectQuestion("吐血 # 便血 # 衄血 # 尿血=8")
		//println msq.lastResult
		assert(msq.lastResult == -1)
		
		assert(msq.questionString == "吐血#便血#衄血#尿血=8")

		assert(msq.baseValue== 8)

		//println msq.questions
		ArrayList ans = ["吐血", "便血", "xxx"]
		assert(msq.answer(ans) == 9)

		assert(msq.answer("吐 血 ") == 8)
		
		assert(msq.lastResult == 8)
	}

	@Test
	public void testSingle() {
		def ssq = new SingleSelectQuestion("低热（37．4～38℃）=4 /中等度热（38．1～39℃）=5 /高热(39．1以上）=6 ")

		assert(ssq.questionString == "低热（37．4～38℃）=4/中等度热（38．1～39℃）=5/高热(39．1以上）=6")

		assert(ssq.answer("低热（37．4～38℃）  ") == 4)
		assert(ssq.answer("中等度热（38．1～39℃）") == 5)
		
		assert(ssq.answer(["低热（37．4～38℃）","中等度热（38．1～39℃）"]) == 5)
	}
	
	@Test
	public void testYesNo(){
		def ynq = new YesNoQuestion(" 斑色紫黑=4 ")
		assert(ynq.questionString == "斑色紫黑=4")
		
		//assert(ynq.answer(true)==4)
		assert(ynq.answer("斑色紫黑 ")==4)
		
		assert(ynq.answer(["斑色紫黑","xxxx"])==4)
		
		assert(ynq.getOptions() == ["斑色紫黑"])
		
	}

	@Test
	public void testQuestionSet(){
		def qset = new QuestionSet("低热（37．4～38℃）=4 /中等度热（38．1～39℃）=5 /高热(39．1以上）=6 @ 漱水不欲咽=4 @ 神昏谵语=6 @ 吐血 # 便血 # 衄血 # 尿血=8 @ 斑色紫黑=4 @ 舌质绛=4 /舌质绛起刺=5")
		assert(qset.questionString == "低热（37．4～38℃）=4/中等度热（38．1～39℃）=5/高热(39．1以上）=6@漱水不欲咽=4@神昏谵语=6@吐血#便血#衄血#尿血=8@斑色紫黑=4@舌质绛=4/舌质绛起刺=5")
		
		def ans = ["低热（37．4～38℃）","吐血","便血","xxx"]
		
		assert(qset.answer(ans) == 13) //4 + 8 + 1
		
		assert qset.subQuestions[0].class.simpleName == "SingleSelectQuestion"
		
		}
}
